package com.ioc;

import com.ioc.config.SpringConfig;
import com.ioc.dao.BookDao;
import com.ioc.dao.UserDao;
import com.ioc.service.UserService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**

 *
 */
public class DITest01 {


    public static void main(String[] args) {
        //让Spring加载配置文件
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
        //方式一：使用名字获取Bean
//        UserDao userDao = (UserDao) ctx.getBean("userDao");
//        userDao.save();

        //方式二：使用类型获取Bean
//        BookDao bookDao = ctx.getBean(BookDao.class);
//        bookDao.save();


        UserService userService = (UserService) ctx.getBean("userService");
        userService.save();


    }



}
